package com.personal.ifanya.infrastructure.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class PropertyService extends PropertyPlaceholderConfigurer {

	private static Map<String, Object> appPropertiesMap;  
	  
    @Override  
    protected void processProperties(ConfigurableListableBeanFactory beanFactory,  
            Properties props)throws BeansException {  
  
        super.processProperties(beanFactory, props);  
        //load properties to ctxPropertiesMap  
        appPropertiesMap = new HashMap<String, Object>();  
        
        Set<Entry<Object,Object>> entrySet = props.entrySet();
        
        for (Entry<Object,Object> item : entrySet) {  
        	if(item != null)
        		appPropertiesMap.put(item.getKey().toString(), item.getValue());  
        }  
    }  
   
    
    public static Object getProperty(String name) {  
        return appPropertiesMap.get(name);  
    }  
	
    public static Integer getInt(String name) {  
        return Integer.valueOf(appPropertiesMap.get(name).toString());  
    } 
    
    public static String getString(String name) {  
        return  appPropertiesMap.get(name).toString();  
    } 
}
